package com.hky.front_end_monitor.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hky.front_end_monitor.constant.Constants;
import com.hky.front_end_monitor.entity.SysFirstContentfulPaint;
import com.hky.front_end_monitor.entity.SysFirstPaint;
import com.hky.front_end_monitor.service.SysFirstContentfulPaintService;
import com.hky.front_end_monitor.mapper.SysFirstContentfulPaintMapper;
import com.hky.front_end_monitor.utils.NumberUtils;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author hello
 * @description 针对表【sys_first_contentful_paint】的数据库操作Service实现
 * @createDate 2022-07-28 22:40:40
 */
@Service
public class SysFirstContentfulPaintServiceImpl extends ServiceImpl<SysFirstContentfulPaintMapper, SysFirstContentfulPaint>
        implements SysFirstContentfulPaintService {
    @Override
    public boolean storeFcp(String uuid, Map map) {
        SysFirstContentfulPaint fcp = new SysFirstContentfulPaint();
        fcp.setSysFirstContentfulPaintId(uuid);
        Map data = ((Map) (map.get(Constants.metricsName.FCP.value)));
        fcp.setStartTime(NumberUtils.toDouble(data.get("startTime")));
        LinkedHashMap entryInfo = (LinkedHashMap) (data).get("entry");
        fcp.setEntryName((String) entryInfo.get("name"));
        fcp.setEntryType((String) entryInfo.get("entryType"));
        fcp.setEntryStartTime(NumberUtils.toDouble(entryInfo.get("startTime")));
        fcp.setEntryDuration(NumberUtils.toDouble(entryInfo.get("duration")));
        return this.save(fcp);
    }
}




